package com.atguigu.msmservice.service.Impl;
import com.atguigu.msmservice.service.MsmService;
import com.atguigu.msmservice.util.SMSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class MsmServiceImpl implements MsmService {

	@Resource
	private RedisTemplate<String, String> redisTemplate;

	@Override
	public boolean send(String phone, String sms_180051135, String code) {
		try {
			//调用阿里云提供的接口发送短信
			SMSUtils.sendMessage("浮生若梦", sms_180051135, phone, code);
			//打印到控制台
			log.info(code);
			//同时将验证码存放在redis中
			redisTemplate.opsForValue().set(phone,code,5, TimeUnit.MINUTES);
			return true;
		} catch (Exception exception) {

			exception.printStackTrace();
		}
		return false;
	}


}
